package cn.com.css.taxInspection.workrisk.controller;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import cn.com.css.taxInspection.common.aop.annotation.LogAnnotation;
import cn.com.css.taxInspection.common.result.DataResult;
import cn.com.css.taxInspection.gt3.entity.DmGySwjgEntity;
import cn.com.css.taxInspection.gt3.entity.JcAjxxEntity;
import cn.com.css.taxInspection.gt3.service.DmGySwjgService;
import cn.com.css.taxInspection.gt3.service.JcAjxxService;
import cn.com.css.taxInspection.system.entity.SysUser;
import cn.com.css.taxInspection.system.service.UserService;
import cn.com.css.taxInspection.system.service.impl.HttpSessionService;
import cn.com.css.taxInspection.util.TsBqUtils;
import cn.com.css.taxInspection.workrisk.entity.WorkriskRisk1Entity;
import cn.com.css.taxInspection.workrisk.service.WorkriskRisk1Service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;

@Controller
@RequestMapping("/workflow/risk1")
public class WorkriskRisk1Controller {
    @Resource
    private WorkriskRisk1Service workriskRisk1Service;
    @Resource
    private HttpSessionService httpSessionService;
    @Resource
    private JcAjxxService jcAjxxService;
    @Resource
    private DmGySwjgService dmGySwjgService;
    @Resource
    private UserService userService;

    @ApiOperation(value = "提醒-个人未读列表")
    @PostMapping("/unreadlist1")
    @RequiresPermissions("workflow:risk:unreadlist1")
    @ResponseBody
    @LogAnnotation(title = "提醒", action = "个人未读列表")
    @DS("oracle")
    public DataResult unreadlist1(@RequestBody WorkriskRisk1Entity workriskRisk1) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String currentUserId = httpSessionService.getCurrentUserId();
        Page<WorkriskRisk1Entity> page = new Page<>(workriskRisk1.getPage(), workriskRisk1.getLimit());
        LambdaQueryWrapper<WorkriskRisk1Entity> queryWrapper = Wrappers.lambdaQuery();
        // 查询条件示例
        queryWrapper.and((wrapper) -> wrapper.or().like(WorkriskRisk1Entity::getRiskManJcry, currentUserId)
                .or().like(WorkriskRisk1Entity::getRiskManSlry, currentUserId)
                .or().like(WorkriskRisk1Entity::getRiskManXary, currentUserId)
                .or().like(WorkriskRisk1Entity::getRiskManTzsry, currentUserId));
        // 稽查案件编号
        if (TsBqUtils.isNotNull(workriskRisk1.getJcajbh())) {
            queryWrapper.like(WorkriskRisk1Entity::getAjbh, workriskRisk1.getJcajbh());
        }
        //查询创建日期
        if (TsBqUtils.isNotNull(workriskRisk1.getStartTime())) {
            queryWrapper.between(WorkriskRisk1Entity::getCreateTime, sdf.parse(workriskRisk1.getStartTime()), sdf.parse(workriskRisk1.getEndTime()));
        }
        queryWrapper.eq(WorkriskRisk1Entity::getRiskType, "6");
        queryWrapper.orderByDesc(WorkriskRisk1Entity::getCreateTime);
        IPage<WorkriskRisk1Entity> iPage = workriskRisk1Service.page(page, queryWrapper);
        List<WorkriskRisk1Entity> records = iPage.getRecords();
        for (WorkriskRisk1Entity workriskRisk1Entity : records) {
            String relevance = workriskRisk1Entity.getRelevance();
            String riskName = workriskRisk1Entity.getRiskName();
            String details = workriskRisk1Entity.getDetails();
            String id = workriskRisk1Entity.getId();
            JcAjxxEntity jcAjxxEntity = jcAjxxService.getByJcajxxuuid(relevance);
            if (TsBqUtils.isNotNull(jcAjxxEntity)) {
                WorkriskRisk1Entity workriskRisk1Entity1 = new WorkriskRisk1Entity();
                workriskRisk1Entity1.setId(id);
                workriskRisk1Entity1.setAjbh(jcAjxxEntity.getJcajbh());
                workriskRisk1Service.updateById(workriskRisk1Entity1);
                BeanUtils.copyProperties(jcAjxxEntity, workriskRisk1Entity);
                workriskRisk1Entity.setRiskName(riskName);
                workriskRisk1Entity.setId(id);
                workriskRisk1Entity.setDetails(details);
            }
        }
        return DataResult.success(iPage);
    }


    @PostMapping("/exportUnreadlist1")
    @ApiOperation(value = "个人提醒-导出")
    @LogAnnotation(title = "个人提醒-导出", action = "个人提醒-导出")
    @ResponseBody
    @DS("oracle")
    public DataResult exportUnreadlist1(@RequestBody WorkriskRisk1Entity workriskRisk1) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String currentUserId = httpSessionService.getCurrentUserId();
        LambdaQueryWrapper<WorkriskRisk1Entity> queryWrapper = Wrappers.lambdaQuery();
        // 查询条件示例
        queryWrapper.and((wrapper) -> wrapper.or().like(WorkriskRisk1Entity::getRiskManJcry, currentUserId)
                .or().like(WorkriskRisk1Entity::getRiskManSlry, currentUserId)
                .or().like(WorkriskRisk1Entity::getRiskManXary, currentUserId)
                .or().like(WorkriskRisk1Entity::getRiskManTzsry, currentUserId));
        // 稽查案件编号
        if (TsBqUtils.isNotNull(workriskRisk1.getJcajbh())) {
            queryWrapper.like(WorkriskRisk1Entity::getAjbh, workriskRisk1.getJcajbh());
        }
        //查询创建日期
        if (TsBqUtils.isNotNull(workriskRisk1.getStartTime())) {
            queryWrapper.between(WorkriskRisk1Entity::getCreateTime, sdf.parse(workriskRisk1.getStartTime()), sdf.parse(workriskRisk1.getEndTime()));
        }
        queryWrapper.eq(WorkriskRisk1Entity::getRiskType, "6");
        queryWrapper.orderByDesc(WorkriskRisk1Entity::getCreateTime);
        List<WorkriskRisk1Entity> workriskRisk1EntityList = workriskRisk1Service.list(queryWrapper);
        return DataResult.success(workriskRisk1EntityList);
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    @ApiOperation(value = "预警提醒-个人已读列表")
    @PostMapping("/readlist1")
    @RequiresPermissions("workflow:risk:readlist1")
    @ResponseBody
    @LogAnnotation(title = "预警提醒", action = "个人已读列表")
    @DS("oracle")
    public DataResult readlist1(@RequestBody WorkriskRisk1Entity workriskRisk1) {
        String currentUserId = httpSessionService.getCurrentUserId();
        Page page = new Page(workriskRisk1.getPage(), workriskRisk1.getLimit());
        LambdaQueryWrapper<WorkriskRisk1Entity> queryWrapper = Wrappers.lambdaQuery();
        // 查询条件示例
        // queryWrapper.like(WorkriskRisk1Entity::getRiskMan1, currentUserId);

        queryWrapper.and((wrapper) -> wrapper.or().like(WorkriskRisk1Entity::getRiskManJcry, currentUserId)
                .or().like(WorkriskRisk1Entity::getRiskManSlry, currentUserId)
                .or().like(WorkriskRisk1Entity::getRiskManXary, currentUserId)
                .or().like(WorkriskRisk1Entity::getRiskManTzsry, currentUserId));
        queryWrapper.isNotNull(WorkriskRisk1Entity::getRiskManJcryRead);
        queryWrapper.isNotNull(WorkriskRisk1Entity::getRiskManSlryRead);
        queryWrapper.isNotNull(WorkriskRisk1Entity::getRiskManXaryRead);
        queryWrapper.isNotNull(WorkriskRisk1Entity::getRiskManTzsryRead);
        IPage<WorkriskRisk1Entity> iPage = workriskRisk1Service.page(page, queryWrapper);
        List<WorkriskRisk1Entity> records = iPage.getRecords();
        for (WorkriskRisk1Entity workriskRisk1Entity : records) {
            String relevance = workriskRisk1Entity.getRelevance();
            String riskName = workriskRisk1Entity.getRiskName();
            String details = workriskRisk1Entity.getDetails();
            String id = workriskRisk1Entity.getId();
            JcAjxxEntity jcAjxxEntity = jcAjxxService.getByJcajxxuuid(relevance);
            if (TsBqUtils.isNotNull(jcAjxxEntity)) {
                WorkriskRisk1Entity wr = new WorkriskRisk1Entity();
                wr.setId(id);
                wr.setAjbh(jcAjxxEntity.getJcajbh());
                workriskRisk1Service.updateById(wr);
                BeanUtils.copyProperties(jcAjxxEntity, workriskRisk1Entity);
                workriskRisk1Entity.setRiskName(riskName);
                workriskRisk1Entity.setDetails(details);
            }
        }
        return DataResult.success(iPage);
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    @ApiOperation(value = "预警提醒-科长岗位")
    @PostMapping("/unreadlist2")
    // @RequiresPermissions("workflow:risk:unreadlist2")
    @ResponseBody
    @LogAnnotation(title = "预警提醒", action = "科长岗位")
    @DS("oracle")
    public DataResult unreadlist2(@RequestBody WorkriskRisk1Entity workriskRisk1) {
        String currentDeptId = httpSessionService.getCurrentDeptId();
        Page page = new Page(workriskRisk1.getPage(), workriskRisk1.getLimit());
        LambdaQueryWrapper<WorkriskRisk1Entity> queryWrapper = Wrappers.lambdaQuery();
        // 查询条件示例
        queryWrapper.eq(WorkriskRisk1Entity::getTaxorgcode, currentDeptId);
        queryWrapper.isNotNull(WorkriskRisk1Entity::getRiskMan2);
        queryWrapper.isNull(WorkriskRisk1Entity::getRiskRead2);
        IPage<WorkriskRisk1Entity> iPage = workriskRisk1Service.page(page, queryWrapper);
        List<WorkriskRisk1Entity> records = iPage.getRecords();
        for (WorkriskRisk1Entity workriskRisk1Entity : records) {
            String relevance = workriskRisk1Entity.getRelevance();
            String riskName = workriskRisk1Entity.getRiskName();
            String id = workriskRisk1Entity.getId();
            JcAjxxEntity jcAjxxEntity = jcAjxxService.getByJcajxxuuid(relevance);
            WorkriskRisk1Entity workriskRisk1Entity1 = new WorkriskRisk1Entity();
            workriskRisk1Entity1.setId(id);
            workriskRisk1Entity1.setAjbh(jcAjxxEntity.getJcajbh());
            workriskRisk1Service.updateById(workriskRisk1Entity1);
            BeanUtils.copyProperties(jcAjxxEntity, workriskRisk1Entity);
            BeanUtils.copyProperties(jcAjxxEntity, workriskRisk1Entity);
            jcAjxxEntity.setRiskName(riskName);
        }
        return DataResult.success(iPage);
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    @ApiOperation(value = "预警提醒-科长岗位已读列表")
    @PostMapping("/readlist2")
    @RequiresPermissions("workflow:risk:readlist2")
    @ResponseBody
    @LogAnnotation(title = "预警提醒", action = "科长岗位已读列表")
    @DS("oracle")
    public DataResult readlist2(@RequestBody WorkriskRisk1Entity workriskRisk1) {
        String currentDeptId = httpSessionService.getCurrentDeptId();
        Page page = new Page(workriskRisk1.getPage(), workriskRisk1.getLimit());
        LambdaQueryWrapper<WorkriskRisk1Entity> queryWrapper = Wrappers.lambdaQuery();
        // 查询条件示例
        queryWrapper.eq(WorkriskRisk1Entity::getTaxorgcode, currentDeptId);
        queryWrapper.isNotNull(WorkriskRisk1Entity::getRiskRead2);
        queryWrapper.isNotNull(WorkriskRisk1Entity::getRiskMan2);
        queryWrapper.isNull(WorkriskRisk1Entity::getCreateTime);
        queryWrapper.orderByDesc(WorkriskRisk1Entity::getCreateTime);
        IPage<WorkriskRisk1Entity> iPage = workriskRisk1Service.page(page, queryWrapper);
        List<WorkriskRisk1Entity> records = iPage.getRecords();
        for (WorkriskRisk1Entity workriskRisk1Entity : records) {
            String relevance = workriskRisk1Entity.getRelevance();
            String riskName = workriskRisk1Entity.getRiskName();
            String id = workriskRisk1Entity.getId();
            JcAjxxEntity jcAjxxEntity = jcAjxxService.getByJcajxxuuid(relevance);
            WorkriskRisk1Entity workriskRisk1Entity1 = new WorkriskRisk1Entity();
            workriskRisk1Entity1.setId(id);
            workriskRisk1Entity1.setAjbh(jcAjxxEntity.getJcajbh());
            workriskRisk1Service.updateById(workriskRisk1Entity1);
            BeanUtils.copyProperties(jcAjxxEntity, workriskRisk1Entity);
            jcAjxxEntity.setRiskName(riskName);
        }
        return DataResult.success(iPage);
    }


    @SuppressWarnings({"rawtypes", "unchecked"})
    @ApiOperation(value = "预警提醒-局长岗未读列表")
    @PostMapping("/unreadlist3")
    @RequiresPermissions("workflow:risk:unreadlist3")
    @ResponseBody
    @LogAnnotation(title = "预警提醒", action = "局长岗未读列表")
    @DS("oracle")
    public DataResult unreadlist3(@RequestBody WorkriskRisk1Entity workriskRisk1) {
        String currentDeptId = httpSessionService.getCurrentDeptId();
        Page page = new Page(workriskRisk1.getPage(), workriskRisk1.getLimit());
        LambdaQueryWrapper<WorkriskRisk1Entity> queryWrapper = Wrappers.lambdaQuery();
        // 查询条件示例
        queryWrapper.like(WorkriskRisk1Entity::getTaxorgcode, currentDeptId.substring(0, 9));
        queryWrapper.isNull(WorkriskRisk1Entity::getRiskRead3);
        queryWrapper.isNotNull(WorkriskRisk1Entity::getRiskMan3);
        IPage<WorkriskRisk1Entity> iPage = workriskRisk1Service.page(page, queryWrapper);
        List<WorkriskRisk1Entity> records = iPage.getRecords();
        for (WorkriskRisk1Entity workriskRisk1Entity : records) {
            String relevance = workriskRisk1Entity.getRelevance();
            String riskName = workriskRisk1Entity.getRiskName();
            String id = workriskRisk1Entity.getId();
            JcAjxxEntity jcAjxxEntity = jcAjxxService.getByJcajxxuuid(relevance);
            if (TsBqUtils.isNotNull(jcAjxxEntity)) {
                WorkriskRisk1Entity workriskRisk1Entity1 = new WorkriskRisk1Entity();
                workriskRisk1Entity1.setId(id);
                workriskRisk1Entity1.setAjbh(jcAjxxEntity.getJcajbh());
                workriskRisk1Service.updateById(workriskRisk1Entity1);
            }
            BeanUtils.copyProperties(jcAjxxEntity, workriskRisk1Entity);
            jcAjxxEntity.setRiskName(riskName);
        }
        return DataResult.success(iPage);
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    @ApiOperation(value = "预警提醒-局长岗位已读列表")
    @PostMapping("/readlist3")
    @RequiresPermissions("workflow:risk:readlist3")
    @ResponseBody
    @LogAnnotation(title = "预警提醒", action = "局长岗位已读列表")
    @DS("oracle")
    public DataResult readlist3(@RequestBody WorkriskRisk1Entity workriskRisk1) {
        String currentDeptId = httpSessionService.getCurrentDeptId();
        Page page = new Page(workriskRisk1.getPage(), workriskRisk1.getLimit());
        LambdaQueryWrapper<WorkriskRisk1Entity> queryWrapper = Wrappers.lambdaQuery();
        // 查询条件示例
        queryWrapper.like(WorkriskRisk1Entity::getTaxorgcode, currentDeptId.substring(0, 9));
        queryWrapper.isNotNull(WorkriskRisk1Entity::getRiskRead3);
        queryWrapper.isNotNull(WorkriskRisk1Entity::getRiskMan3);
        IPage<WorkriskRisk1Entity> iPage = workriskRisk1Service.page(page, queryWrapper);
        List<WorkriskRisk1Entity> records = iPage.getRecords();
        for (WorkriskRisk1Entity workriskRisk1Entity : records) {
            String relevance = workriskRisk1Entity.getRelevance();
            String riskName = workriskRisk1Entity.getRiskName();
            String id = workriskRisk1Entity.getId();
            JcAjxxEntity jcAjxxEntity = jcAjxxService.getByJcajxxuuid(relevance);
            if (TsBqUtils.isNotNull(jcAjxxEntity)) {
                WorkriskRisk1Entity workriskRisk1Entity1 = new WorkriskRisk1Entity();
                workriskRisk1Entity1.setId(id);
                workriskRisk1Entity1.setAjbh(jcAjxxEntity.getJcajbh());
                workriskRisk1Service.updateById(workriskRisk1Entity1);
            }
            BeanUtils.copyProperties(jcAjxxEntity, workriskRisk1Entity);
            jcAjxxEntity.setRiskName(riskName);
        }
        return DataResult.success(iPage);
    }

    @ApiOperation(value = "预警提醒-读取")
    @PostMapping("/read")
    @ResponseBody
    @LogAnnotation(title = "预警提醒", action = "读取")
    @DS("oracle")
    public DataResult read(@RequestBody WorkriskRisk1Entity workriskRisk1) {
        String currentUserId = httpSessionService.getCurrentUserId();
        String id = workriskRisk1.getId();
        if (TsBqUtils.isNull(id)) {
            return DataResult.fail("id不能为NULL");
        }
        String riskRead = workriskRisk1.getRiskRead();
        if (TsBqUtils.isNull(riskRead)) {
            return DataResult.fail("riskRead不能为NULL");
        }
        WorkriskRisk1Entity workriskRisk1Entity = workriskRisk1Service.getById(id);
        workriskRisk1Entity.setRiskRead1(currentUserId);
        workriskRisk1Entity.setUpdateId(currentUserId);
        workriskRisk1Entity.setUpdateTime(new Date());
        workriskRisk1Service.updateById(workriskRisk1Entity);
        return DataResult.success();
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    @ApiOperation(value = "预警提醒")
    @PostMapping("/sectionChief")
    @ResponseBody
    @LogAnnotation(title = "预警提醒", action = "科长权限")
    @DS("oracle")
    public DataResult sectionChief(@RequestBody WorkriskRisk1Entity workriskRisk1) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 时间，科室，人员
        String currentDeptId = httpSessionService.getCurrentDeptId();
        String taxorgcode = workriskRisk1.getTaxorgcode();
        String taxCode;
        if (TsBqUtils.isNull(taxorgcode)) {
            taxCode = currentDeptId;
        } else {
            taxCode = taxorgcode;
        }
        Page page = new Page(workriskRisk1.getPage(), workriskRisk1.getLimit());
        LambdaQueryWrapper<WorkriskRisk1Entity> queryWrapper = Wrappers.lambdaQuery();
        // 查询条件示例
        queryWrapper.eq(WorkriskRisk1Entity::getTaxorgcode, taxCode);
        if (!StringUtils.isEmpty(workriskRisk1.getStartTime())) {
            queryWrapper.gt(WorkriskRisk1Entity::getCreateTime, sdf.parse(workriskRisk1.getStartTime()));
        }
        if (!StringUtils.isEmpty(workriskRisk1.getEndTime())) {
            queryWrapper.lt(WorkriskRisk1Entity::getCreateTime, sdf.parse(workriskRisk1.getEndTime()));
        }

        if (!StringUtils.isEmpty(workriskRisk1.getRiskMan1())) {
            queryWrapper.eq(WorkriskRisk1Entity::getRiskMan1, workriskRisk1.getRiskMan1());
        }
        if (!StringUtils.isEmpty(workriskRisk1.getTaxorgcode())) {
            queryWrapper.eq(WorkriskRisk1Entity::getTaxorgcode, workriskRisk1.getTaxorgcode());
        }
        queryWrapper.orderByDesc(WorkriskRisk1Entity::getCreateTime);
        IPage<WorkriskRisk1Entity> iPage = workriskRisk1Service.page(page, queryWrapper);
        List<WorkriskRisk1Entity> records = iPage.getRecords();
        for (WorkriskRisk1Entity workriskRisk1Entity : records) {
            String id = workriskRisk1Entity.getId();
            String relevance = workriskRisk1Entity.getRelevance();
            JcAjxxEntity jcAjxxEntity = jcAjxxService.getByJcajxxuuid(relevance);
            if (TsBqUtils.isNotNull(jcAjxxEntity)) {
                WorkriskRisk1Entity workriskRisk1Entity1 = new WorkriskRisk1Entity();
                workriskRisk1Entity1.setId(id);
                workriskRisk1Entity1.setAjbh(jcAjxxEntity.getJcajbh());
                workriskRisk1Service.updateById(workriskRisk1Entity1);
            }
            String riskMan1 = workriskRisk1Entity.getRiskMan1();
            String riskRead1 = workriskRisk1Entity.getRiskRead1();
            if (TsBqUtils.isNotNull(riskMan1)) {
                SysUser sysUser = userService.getUser(riskMan1);
                if (TsBqUtils.isNotNull(sysUser)) {
                    riskMan1 = sysUser.getNickName();
                }
            }
            if (TsBqUtils.isNull(riskRead1)) {
                riskRead1 = "未读";
            } else {
                riskRead1 = "已读";
            }
            workriskRisk1Entity.setRiskMan1(riskMan1);
            workriskRisk1Entity.setRiskRead1(riskRead1);
        }
        return DataResult.success(iPage);
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    @ApiOperation(value = "预警提醒1")
    @PostMapping("/sectionChief1")
    @ResponseBody
    @LogAnnotation(title = "预警提醒1", action = "局长权限")
    @DS("oracle")
    public DataResult sectionChief1(@RequestBody WorkriskRisk1Entity workriskRisk1) throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        // 时间，科室，人员
        String currentDeptId = httpSessionService.getCurrentDeptId();
        String taxorgcode = workriskRisk1.getTaxorgcode();
        Page page = new Page(workriskRisk1.getPage(), workriskRisk1.getLimit());
        LambdaQueryWrapper<WorkriskRisk1Entity> queryWrapper = Wrappers.lambdaQuery();
        // 查询条件示例
        if (!StringUtils.isEmpty(taxorgcode)) {
            queryWrapper.eq(WorkriskRisk1Entity::getTaxorgcode, taxorgcode);
        } else {
            queryWrapper.like(WorkriskRisk1Entity::getTaxorgcode, currentDeptId.substring(0, 9));
        }
        if (!StringUtils.isEmpty(workriskRisk1.getStartTime())) {
            queryWrapper.gt(WorkriskRisk1Entity::getCreateTime, sdf.parse(workriskRisk1.getStartTime()));
        }
        if (!StringUtils.isEmpty(workriskRisk1.getEndTime())) {
            queryWrapper.lt(WorkriskRisk1Entity::getCreateTime, sdf.parse(workriskRisk1.getEndTime()));
        }
        if (!StringUtils.isEmpty(workriskRisk1.getRiskMan1())) {
            queryWrapper.eq(WorkriskRisk1Entity::getRiskMan1, workriskRisk1.getRiskMan1());
        }
        if (!StringUtils.isEmpty(workriskRisk1.getTaxorgcode())) {
            queryWrapper.eq(WorkriskRisk1Entity::getTaxorgcode, workriskRisk1.getTaxorgcode());
        }
        queryWrapper.orderByDesc(WorkriskRisk1Entity::getCreateTime);
        IPage<WorkriskRisk1Entity> iPage = workriskRisk1Service.page(page, queryWrapper);
        List<WorkriskRisk1Entity> records = iPage.getRecords();
        for (WorkriskRisk1Entity workriskRisk1Entity : records) {
            String riskMan1 = workriskRisk1Entity.getRiskMan1();
            String riskRead1 = workriskRisk1Entity.getRiskRead1();
            String id = workriskRisk1Entity.getId();
            String relevance = workriskRisk1Entity.getRelevance();
            JcAjxxEntity jcAjxxEntity = jcAjxxService.getByJcajxxuuid(relevance);
            if (TsBqUtils.isNotNull(jcAjxxEntity)) {
                WorkriskRisk1Entity workriskRisk1Entity1 = new WorkriskRisk1Entity();
                workriskRisk1Entity1.setId(id);
                workriskRisk1Entity1.setAjbh(jcAjxxEntity.getJcajbh());
                workriskRisk1Service.updateById(workriskRisk1Entity1);
            }
            if (TsBqUtils.isNotNull(riskMan1)) {
                SysUser sysUser = userService.getUser(riskMan1);
                if (TsBqUtils.isNotNull(sysUser)) {
                    riskMan1 = sysUser.getNickName();
                }
            }
            if (TsBqUtils.isNull(riskRead1)) {
                riskRead1 = "未读";
            } else {
                riskRead1 = "已读";
            }
            workriskRisk1Entity.setRiskMan1(riskMan1);
            workriskRisk1Entity.setRiskRead1(riskRead1);
        }
        return DataResult.success(iPage);
    }

    @SuppressWarnings({"rawtypes", "unchecked"})
    @ApiOperation(value = "预警提醒")
    @PostMapping("/directorGeneral")
    @ResponseBody
    @LogAnnotation(title = "预警提醒", action = "局长权限")
    @DS("oracle")
    public DataResult directorGeneral(@RequestBody WorkriskRisk1Entity workriskRisk1) {
        String currentDeptId = httpSessionService.getCurrentDeptId();
        DmGySwjgEntity dmGySwjgEntity = dmGySwjgService.getSwjgDm(currentDeptId);
        String sjswjgDm = dmGySwjgEntity.getSjswjgDm();
        String taxorgcode = workriskRisk1.getTaxorgcode();
        String taxCode;
        if (TsBqUtils.isNull(taxorgcode)) {
            taxCode = sjswjgDm;
        } else {
            taxCode = taxorgcode;
        }
        Page page = new Page(workriskRisk1.getPage(), workriskRisk1.getLimit());
        QueryWrapper<WorkriskRisk1Entity> queryWrapper = new QueryWrapper<>();
        LambdaQueryWrapper<WorkriskRisk1Entity> lambdaQueryWrapper = queryWrapper.select("count(1) AS count,TAXORGCODE as TAXORGCODE").lambda().groupBy(WorkriskRisk1Entity::getTaxorgcode);
        // 查询条件示例
        lambdaQueryWrapper.like(WorkriskRisk1Entity::getTaxorgcode, taxCode.substring(0, 9));
        IPage<WorkriskRisk1Entity> iPage = workriskRisk1Service.page(page, queryWrapper);
        List<WorkriskRisk1Entity> records = iPage.getRecords();
        for (WorkriskRisk1Entity workriskRisk1Entity : records) {
            String _taxorgcode = workriskRisk1Entity.getTaxorgcode();
            DmGySwjgEntity _dmGySwjgEntity = dmGySwjgService.getSwjgDm(_taxorgcode);
            String swjgmc = _dmGySwjgEntity.getSwjgmc();
            workriskRisk1Entity.setSwjg_dm(swjgmc);
        }
        return DataResult.success(iPage);
    }

}
